<?php
namespace app\common\config\logic;


use app\common\BaseLogic;

/**
 * 包含
 * 1、系统基本配置
 * 2、登录配置
 * Class SystemConfig
 * @package app\common\logic
 */
class ConfigSystem extends BaseLogic
{
    public function getConfigItem($title)
    {
        $cacheName = 'api_config_item:'.$title;
        $data = $this->redis->hGetAll($cacheName);
        if (empty_hGet($data)) {
            $where = [];
            $where['title'] = $title;
            $model = new \app\common\config\model\ConfigSystem();
            $row = $model->where($where)->find();
            if ($row) {
                $data = $row->content;
                $data['id'] = 1;
                $this->redis->hMSet($cacheName, $data);
            } else {
                $data = [];
                $this->redis->HMSet($cacheName, ['id'=>0]);
            }
        }

        return $data;
    }

    public function resetConfigItemCache($title, $config=[]) {
        $cacheName = 'api_config_item:'.$title;
        $this->redis->multi();
        $this->redis->del($cacheName);
        !empty($config) && $this->redis->hMSet($cacheName, $config);
        $this->redis->exec();
    }
}